﻿using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using WeForms.Design;

namespace WeForms.View
{
    [ToolboxItem(false)]
    public class WeTabView : TouchContainerControl
    {
        public WeTabContainer ParentContainer { get; set; }

        protected WeTabView()
        {
            Padding = new Padding(5);
            base.AutoScroll = true;
            
            ViewSpecificControls = new WeTabSideBarControlList();
            base.Font = new Font("Arial", 19, GraphicsUnit.Pixel);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                while (ViewSpecificControls.Count > 0)
                {
                    ViewSpecificControls[0].Dispose();
                    ViewSpecificControls.RemoveAt(0);
                }
            }
            base.Dispose(disposing);
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [Editor(typeof(WeTabSideBarControlListEditor), typeof(UITypeEditor))]
        public WeTabSideBarControlList ViewSpecificControls { get; private set; }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (DesignMode)
            {
                using (Pen p = new Pen(SystemColors.ControlDark))
                {
                    p.DashStyle = DashStyle.Dash;
                    e.Graphics.DrawRectangle(p,
                                             new Rectangle(AutoScrollPosition.X, AutoScrollPosition.Y,
                                                           WeTabTheme.FullScreenAppSize.Width - WeTabTheme.SideBarWidth,
                                                           WeTabTheme.FullScreenAppSize.Height));
                }
            }
        }

        protected override void OnAutoSizeChanged(System.EventArgs e)
        {
            base.OnAutoSizeChanged(e);
            PerformAutoScale();
            PerformLayout();
        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            if (AutoSize)
            {
                width = WeTabTheme.FullScreenAppSize.Width - WeTabTheme.SideBarWidth;
            } 
            base.SetBoundsCore(x, y, width, height, specified);
        }

        /// <summary>
        /// Called before the view gets showed within the view.
        /// </summary>
        public virtual void OnViewActivating()
        {

        }

        /// <summary>
        /// Called after the view got activated.
        /// </summary>
        public virtual void OnViewActivated()
        {

        }

        /// <summary>
        /// Called before the view gets deactivated.
        /// </summary>
        public virtual void OnViewDeactivating()
        {

        }

        /// <summary>
        /// Called after the view got deactivated.
        /// </summary>
        public virtual void OnViewDeactivated()
        {

        }

    }
}
